package com.ly.base.chapter01;


import com.ly.base.chapter02.AAAFuncCitation.Student;

import java.util.ArrayList;
import java.util.List;

/**
 * 函数式编程基础学习day01
 *
 * 函数式编程概念: 行为参数化
 */
public class Demo01 {
    //1、定义接口
    interface Lambda{
        boolean test(Student student);//定义方法
    }
    //2、定义方法---需要传递接口对象(规则)
    static List<Student> filter0(List<Student> students, Lambda lambda){
        List<Student> result = new ArrayList<>();
        for (Student student : students) {
            if (lambda.test(student)){
                result.add(student);
            }
        }
        return result;
    }
    //3、使用
    public static void main(String[] args) {
        List<Student> students = new ArrayList<>();
        students.add(new Student("张三",17,"男"));
        students.add(new Student("李四",24,"男"));
        students.add(new Student("小美",16,"女"));

        //使用函数
        //规则1：性别男
        System.out.println(filter0(students,student -> student.getSex().equals("男")));
        //规则2：年龄是否小于18
        System.out.println(filter0(students,student -> student.getAge() <= 18));

    }
}
